<template>
  <div style="width: 1200px;margin: 0 auto">
    <el-row>
      <el-col span="24">
        <div id="server_top">
          <p style="font-size: 32px;font-weight: bold" align="center">订单管理</p>
        </div>
      </el-col>
    </el-row>
    <el-card >
      <template  >
        <el-table :data="orderArr">
          <el-table-column type="index" label="编号"></el-table-column>
          <el-table-column prop="serialNumber" label="订单编号" align="center" width="120"></el-table-column>
          <el-table-column prop="username" label="陪诊员姓名" align="center" width="120"></el-table-column>
          <el-table-column prop="productName" label="商品名字" align="center" width="120"></el-table-column>
          <el-table-column prop="price" label="价格" align="center" width="120"></el-table-column>
<!--          <el-table-column label="订单状态" align="center" width="120">
            <template slot-scope="scope">
              <span>{{ state[scope.row.state] }}</span>
            </template>
          </el-table-column>-->
          <el-table-column prop="state" label="订单状态" align="center" width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.state === 0">待接单</span>
              <span v-if="scope.row.state === 1">订单已完成</span>
              <span v-else-if="scope.row.state === 2">已接单</span>
              <span v-else-if="scope.row.state === 3">订单已取消</span>
              <span v-else-if="scope.row.state === 4">等待同意退款</span>
            </template>
          </el-table-column>
          <el-table-column prop="gmtCreate" label="创建时间" align="center" width="170" :formatter="formatDate"></el-table-column>
          <el-table-column prop="gmtPay" label="下单时间" align="center" width="170" :formatter="formatDate"></el-table-column>
<!--          <el-table-column label="操作">
            <template slot-scope="scope">
              &lt;!&ndash;          <el-button type="danger" @click="openDeleteConfirm(scope.row)">修改</el-button>&ndash;&gt;
&lt;!&ndash;              <el-button type="danger" @click="openDeleteConfirm(scope.row)">删除</el-button>&ndash;&gt;
&lt;!&ndash;              <el-button type="danger" size="small">取消订单</el-button>&ndash;&gt;
              <el-button type="primary" @click="pinglun(scope.row)">评价</el-button>
              <el-button :plain="true" @click="openVn(scope.row)">退款</el-button>
            </template>
          </el-table-column>-->
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="primary" :disabled="scope.row.state !== 1" @click="pinglun(scope.row)">评价</el-button>
              <el-button :plain="true" :disabled="scope.row.state === 1 || scope.row.state === 3 || scope.row.state === 4" @click="openVn(scope.row)">退款</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </el-card>

  </div>
</template>
<script>
import TokenAxios from "@/http/TokenAxios";
import BaseUrl from "@/http/BaseUrl";

export default {
  methods: {
    openVn(order) {
      const h = this.$createElement;
      console.log(this.orderArr.serialNumber)
      console.log(order.serialNumber)
      // let param={serialNumber:order.serialNumber,state:order.state}
      debugger
      TokenAxios.post(BaseUrl.ORDER+'/refund/'+order.id+'/refund').then((response) => {
        debugger
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          debugger
          this.$message.success('等待商家同意退款,给您带来不便,敬请谅解!');
          this.orderList();
        } else {
          this.$message.error(jsonResult.message);
        }
      });
    },

    handleClick(row) {
      console.log(row);
    },

    formatDate(row,column){
      let data = row[column.property]
      if(data == null){
        return null
      }
      let dt = new Date(data)
      return dt.getFullYear()+'-'+(dt.getMonth()+1)+'-'+dt.getDate()+' '+dt.getHours()+':'+dt.getMinutes()+':'+dt.getSeconds()
    },

    pinglun(order){
      this.$router.push({name:"evaluate", params:{id:order.id}})
    },

    loadOrderList(){
      debugger
      let loginInfo = JSON.parse(localStorage.getItem("loginInfo"));
      TokenAxios.get(BaseUrl.ORDER+'/orders/userId?userId='+loginInfo.id).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.tableData = jsonResult.data;
        }
      })
    },

    orderList(){
      TokenAxios.get(BaseUrl.ORDER+'/orders/').then((response)=>{
        if (response.data.state==20000){
          debugger
          this.orderArr=response.data.data;
          console.log(response.data.data)
          console.log(this.orderArr)
        }
      })
    },
    openDeleteConfirm(order) {
      let message = '此操作将永久删除【' + order.serialNumber + '】类别，是否继续？';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(order);
      }).catch(() => {
      });
    },
    handleDelete(order) {
      let url = BaseUrl.ORDER+'/orders/' + order.id ;
      console.log('url = ' + url);

      TokenAxios.post(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.$message({
            message: '删除成功！',
            type: 'success'
          });
          this.orderList();
        } else {
          this.$message.error(jsonResult.message);
        }
      });
    },
  },

  data() {
    return {
      state:['待接单','已完成','已接单','已取消','审核中'],
      orderArr:[

      ],
    }
  },


  mounted(){
    this.orderList();
  }
}
</script>

<style scoped>
[v-cloak] {
  display: none;
}

/*伪类选择器(未访问|访问过   |悬停  |点击)
       link |visited|hover|active*/
.syd1:link {
  color: white
}

.syd1:visited {
  color: white
}

.syd1:hover {
  color: beige
}

.syd1:active {
  color: white
}

.syd1 {
  text-decoration: none;
}
</style>
